<?php

namespace App\Http\Controllers\Home;

use App\Http\Controllers\Controller;
use DB;
use Illuminate\Http\Request;
use Crypt;
class registerController extends Controller
{
    public function index()
    {
        return view('home/register/register');
    }



    public function doRegister(Request $request)
    {
        $data = $request -> except('_token');
        //dd($data);
        //if()
        //判断手机号是否存在
        $res = DB::table('user') -> where('phone',$data['formBean_username']) -> first();
        //dd($res);


        $password = $data['formBean_password'];
        $cpassword = $data['checkPassword'];
        //dd($cpassword);
        if($password != $cpassword )
        {
            return '两次密码输入不一样，请返回并重新输入';
        }


        $datas['phone'] = $data['formBean_username'];

       $datas['password'] = Crypt::encrypt($data['formBean_password']);

        //dd($datas);
        $datas['manage'] = 0;
        $res = DB::table('user') -> insert($datas);
        if($res)
        {
        return redirect('home/login/login') -> with(['info' => '注册成功']);
        }
    }
}